package com.echat.core.task;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.net.InetAddress;

@Component
@Slf4j
public class PingUtils {
    public static void main(String[] args) {
        String address = "192.168.10.255";
        if (pingAddr(address)) {
            log.debug(address + "连接畅通");

        } else {
            log.error(address + "连接失败......5分钟后重试");
        }
    }

    public static boolean pingAddr(String address) {
        //超时时间 3 秒以上
        int timeOut = 3000;
        boolean status = false;
        try {
            status = InetAddress.getByName(address).isReachable(timeOut);
        } catch (IOException e) {
            log.error("ping请求过程异常", e);
        }

        return status;
    }
}
